ga.core.selection
Class TournamentSelector<T extends IIndividual<T>>

java.lang.Object
  extended by ga.core.selection.TournamentSelector<T>
Type Parameters:
T - The generic type of individuals.
All Implemented Interfaces:
ISelector<T>

public class TournamentSelector<T extends IIndividual<T>>
extends java.lang.Object
implements ISelector<T>

Implementation of a tournament selector. This will take a n random individuals and only the best of these n individuals will be selected.

n is the tournament size.

Since:
11.08.2012
Author:
Stephan Dreyer

Field Summary
private  boolean allowDuplicates
           
private  boolean replaceOldOnInsert
           
private static int SELECTED_INDIVIDUALS
           
private  int tournamentSize
           
 
Constructor Summary
TournamentSelector(int tournamentSize)
          Create a new tournament selector with the given tournament size.
 
Method Summary
 int getTournamentSize()
          Getter for the tournament size.
 void insert(IndividualList<T> list, IPopulation<T> population, boolean useEliteStrategy)
          Inserts individuals into the population.
 IndividualList<T> select(IPopulation<T> population)
          Selects individuals from the population.
 void setReplaceOldOnInsert(boolean replaceOldOnInsert)
          Activate/deactivate the behavior of replacing individuals during insertion.
 void setTournamentSize(int tournamentSize)
          Sets the tournament size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECTED_INDIVIDUALS

private static final int SELECTED_INDIVIDUALS
See Also:
Constant Field Values

tournamentSize

private int tournamentSize

replaceOldOnInsert

private boolean replaceOldOnInsert

allowDuplicates

private final boolean allowDuplicates
See Also:
Constant Field Values
Constructor Detail

TournamentSelector

public TournamentSelector(int tournamentSize)
Create a new tournament selector with the given tournament size.

Parameters:
tournamentSize - The tournament size.
Since:
11.08.2012
Method Detail

select

public IndividualList<T> select(IPopulation<T> population)
Description copied from interface: ISelector
Selects individuals from the population.

Specified by:
select in interface ISelector<T extends IIndividual<T>>
Parameters:
population - The population to select from.
Returns:
The selected individuals.

setReplaceOldOnInsert

public void setReplaceOldOnInsert(boolean replaceOldOnInsert)
Activate/deactivate the behavior of replacing individuals during insertion. If deactivated, the population will grow with each insertion.

Parameters:
replaceOldOnInsert - Replace or not.
Since:
11.08.2012

setTournamentSize

public void setTournamentSize(int tournamentSize)
Sets the tournament size.

Parameters:
tournamentSize - The tournament size.
Since:
11.08.2012

getTournamentSize

public int getTournamentSize()
Getter for the tournament size.

Returns:
The tournament size.
Since:
11.08.2012

insert

public void insert(IndividualList<T> list,
                   IPopulation<T> population,
                   boolean useEliteStrategy)
Description copied from interface: ISelector
Inserts individuals into the population.

Specified by:
insert in interface ISelector<T extends IIndividual<T>>
Parameters:
list - The individuals to insert.
population - The population to insert to.
useEliteStrategy - Use the elite strategy if true. That will prevent the elite from being replaced during insertion.